<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="用户序列" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户序列"></el-input>
    </el-form-item>
    <el-form-item label="用户名" prop="userName">
      <el-input v-model="dataForm.userName" placeholder="用户名"></el-input>
    </el-form-item>
    <el-form-item label="部门序列" prop="depId">
      <el-input v-model="dataForm.depId" placeholder="部门序列"></el-input>
    </el-form-item>
    <el-form-item label="角色序列" prop="roleId">
      <el-input v-model="dataForm.roleId" placeholder="角色序列"></el-input>
    </el-form-item>
    <el-form-item label="档案状态" prop="state">
      <el-input v-model="dataForm.state" placeholder="档案状态"></el-input>
    </el-form-item>
    <el-form-item label="性别" prop="sex">
      <el-input v-model="dataForm.sex" placeholder="性别"></el-input>
    </el-form-item>
    <el-form-item label="身份证" prop="idcard">
      <el-input v-model="dataForm.idcard" placeholder="身份证"></el-input>
    </el-form-item>
    <el-form-item label="籍贯" prop="address">
      <el-input v-model="dataForm.address" placeholder="籍贯"></el-input>
    </el-form-item>
    <el-form-item label="家庭住址" prop="homeAddress">
      <el-input v-model="dataForm.homeAddress" placeholder="家庭住址"></el-input>
    </el-form-item>
    <el-form-item label="毕业院校" prop="school">
      <el-input v-model="dataForm.school" placeholder="毕业院校"></el-input>
    </el-form-item>
    <el-form-item label="专业" prop="subject">
      <el-input v-model="dataForm.subject" placeholder="专业"></el-input>
    </el-form-item>
    <el-form-item label="学历" prop="degree">
      <el-input v-model="dataForm.degree" placeholder="学历"></el-input>
    </el-form-item>
    <el-form-item label="社保卡" prop="socialNumber">
      <el-input v-model="dataForm.socialNumber" placeholder="社保卡"></el-input>
    </el-form-item>
    <el-form-item label="开户银行" prop="bank">
      <el-input v-model="dataForm.bank" placeholder="开户银行"></el-input>
    </el-form-item>
    <el-form-item label="银行卡号" prop="bankNumber">
      <el-input v-model="dataForm.bankNumber" placeholder="银行卡号"></el-input>
    </el-form-item>
    <el-form-item label="薪酬标准" prop="payId">
      <el-input v-model="dataForm.payId" placeholder="薪酬标准"></el-input>
    </el-form-item>
    <el-form-item label="照片地址" prop="photo">
      <el-input v-model="dataForm.photo" placeholder="照片地址"></el-input>
    </el-form-item>
    <el-form-item label="简历信息" prop="introduce">
      <el-input v-model="dataForm.introduce" placeholder="简历信息"></el-input>
    </el-form-item>
    <el-form-item label="家庭信息" prop="family">
      <el-input v-model="dataForm.family" placeholder="家庭信息"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="comment">
      <el-input v-model="dataForm.comment" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item label="电话号码" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="电话号码"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="date">
      <el-input v-model="dataForm.date" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="邮箱" prop="email">
      <el-input v-model="dataForm.email" placeholder="邮箱"></el-input>
    </el-form-item>
    <el-form-item label="政治面貌" prop="political">
      <el-input v-model="dataForm.political" placeholder="政治面貌"></el-input>
    </el-form-item>
    <el-form-item label="登记人" prop="creatId">
      <el-input v-model="dataForm.creatId" placeholder="登记人"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          userId: '',
          userName: '',
          depId: '',
          roleId: '',
          state: '',
          sex: '',
          idcard: '',
          address: '',
          homeAddress: '',
          school: '',
          subject: '',
          degree: '',
          socialNumber: '',
          bank: '',
          bankNumber: '',
          payId: '',
          photo: '',
          introduce: '',
          family: '',
          comment: '',
          phone: '',
          date: '',
          email: '',
          political: '',
          userCode: 0,
          creatId: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '用户序列不能为空', trigger: 'blur' }
          ],
          userName: [
            { required: true, message: '用户名不能为空', trigger: 'blur' }
          ],
          depId: [
            { required: true, message: '部门序列不能为空', trigger: 'blur' }
          ],
          roleId: [
            { required: true, message: '角色序列不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '档案状态不能为空', trigger: 'blur' }
          ],
          sex: [
            { required: true, message: '性别不能为空', trigger: 'blur' }
          ],
          idcard: [
            { required: true, message: '身份证不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '籍贯不能为空', trigger: 'blur' }
          ],
          homeAddress: [
            { required: true, message: '家庭住址不能为空', trigger: 'blur' }
          ],
          school: [
            { required: true, message: '毕业院校不能为空', trigger: 'blur' }
          ],
          subject: [
            { required: true, message: '专业不能为空', trigger: 'blur' }
          ],
          degree: [
            { required: true, message: '学历不能为空', trigger: 'blur' }
          ],
          socialNumber: [
            { required: true, message: '社保卡不能为空', trigger: 'blur' }
          ],
          bank: [
            { required: true, message: '开户银行不能为空', trigger: 'blur' }
          ],
          bankNumber: [
            { required: true, message: '银行卡号不能为空', trigger: 'blur' }
          ],
          payId: [
            { required: true, message: '薪酬标准不能为空', trigger: 'blur' }
          ],
          photo: [
            { required: true, message: '照片地址不能为空', trigger: 'blur' }
          ],
          introduce: [
            { required: true, message: '简历信息不能为空', trigger: 'blur' }
          ],
          family: [
            { required: true, message: '家庭信息不能为空', trigger: 'blur' }
          ],
          comment: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '电话号码不能为空', trigger: 'blur' }
          ],
          date: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          email: [
            { required: true, message: '邮箱不能为空', trigger: 'blur' }
          ],
          political: [
            { required: true, message: '政治面貌不能为空', trigger: 'blur' }
          ],
          creatId: [
            { required: true, message: '登记人不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.userCode = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.userCode) {
            this.$http({
              url: this.$http.adornUrl(`/code/userinfo/info/${this.dataForm.userCode}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.userInfo.userId
                this.dataForm.userName = data.userInfo.userName
                this.dataForm.depId = data.userInfo.depId
                this.dataForm.roleId = data.userInfo.roleId
                this.dataForm.state = data.userInfo.state
                this.dataForm.sex = data.userInfo.sex
                this.dataForm.idcard = data.userInfo.idcard
                this.dataForm.address = data.userInfo.address
                this.dataForm.homeAddress = data.userInfo.homeAddress
                this.dataForm.school = data.userInfo.school
                this.dataForm.subject = data.userInfo.subject
                this.dataForm.degree = data.userInfo.degree
                this.dataForm.socialNumber = data.userInfo.socialNumber
                this.dataForm.bank = data.userInfo.bank
                this.dataForm.bankNumber = data.userInfo.bankNumber
                this.dataForm.payId = data.userInfo.payId
                this.dataForm.photo = data.userInfo.photo
                this.dataForm.introduce = data.userInfo.introduce
                this.dataForm.family = data.userInfo.family
                this.dataForm.comment = data.userInfo.comment
                this.dataForm.phone = data.userInfo.phone
                this.dataForm.date = data.userInfo.date
                this.dataForm.email = data.userInfo.email
                this.dataForm.political = data.userInfo.political
                this.dataForm.creatId = data.userInfo.creatId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/code/userinfo/${!this.dataForm.userCode ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'userId': this.dataForm.userId,
                'userName': this.dataForm.userName,
                'depId': this.dataForm.depId,
                'roleId': this.dataForm.roleId,
                'state': this.dataForm.state,
                'sex': this.dataForm.sex,
                'idcard': this.dataForm.idcard,
                'address': this.dataForm.address,
                'homeAddress': this.dataForm.homeAddress,
                'school': this.dataForm.school,
                'subject': this.dataForm.subject,
                'degree': this.dataForm.degree,
                'socialNumber': this.dataForm.socialNumber,
                'bank': this.dataForm.bank,
                'bankNumber': this.dataForm.bankNumber,
                'payId': this.dataForm.payId,
                'photo': this.dataForm.photo,
                'introduce': this.dataForm.introduce,
                'family': this.dataForm.family,
                'comment': this.dataForm.comment,
                'phone': this.dataForm.phone,
                'date': this.dataForm.date,
                'email': this.dataForm.email,
                'political': this.dataForm.political,
                'userCode': this.dataForm.userCode || undefined,
                'creatId': this.dataForm.creatId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
